<template>
  
  <div id="reward-home">
      <div style="background-color:#f0f0f0;">

      <a-menu mode="horizontal">
        <a-sub-menu>
            <span slot="title" class="submenu-title-wrapper" >
              <a-avatar :src="userinfo.avatar" style="margin-left:0.25rem; margin-right:0.55rem;" />
              {{ usertitle }} 
            </span>
            <a-menu-item-group title="应用中心">
            <a-menu-item key="setting:1" :to="`/stock/message`"  @click="redirectView('/stock/message')" >
                审批
            </a-menu-item>
            <a-menu-item key="setting:2" :to="`/stock/workspace`" @click="redirectView('/stock/workspace')" >
                工作台
            </a-menu-item>
            <a-menu-item key="setting:3" :to="`/stock/ranking`" @click="redirectView('/stock/ranking')" >
                排行榜
            </a-menu-item>
            <a-menu-item key="setting:4" :to="`/stock/setting`"  >
                系统设置
            </a-menu-item>
            </a-menu-item-group>
        </a-sub-menu>
      </a-menu>

      <a-row :gutter="24" style="background:#fbf9fe;">
        <keep-alive>
            <a-col :xl="24" :lg="24" :md="24" :sm="24" :xs="24" style="background-color:#f0f0f0;">

              <div id="" class="" style="padding-left:2.75rem;padding-top:0.25rem;padding-bottom:0.25rem;background-color:#fefefe;" >
                <a-breadcrumb>
                  <template v-for="(elem,index) in breadcrumb">
                    <a-breadcrumb-item :key="elem.icon" :index="index" >
                      <a-icon :type="elem.icon" />
                      <span @click="redirectView(elem.path)">{{ elem.text }}</span>
                    </a-breadcrumb-item>
                  </template>
                </a-breadcrumb>
              </div>

              <div style="background-color:#f0f0f0;">
                <div id="legal-apply-content" class="reward-apply-content" style="height:auto; background:#fbf9fe; margin-top:0px; margin-left: 2.5rem; margin-right: 2.5rem; margin-bottom: 5rem; border: 1px solid #f0f0f0; front-size: 1rem;" >
                <div style="width:100%;margin-left:0px;margin-right:0px;background:#fbf9fe;">

                    <div class="reward-top-button" style="margin-top:20px;margin-bottom:20px; margin-left:20px; background:#fbf9fe;">
                        <a-input-search v-model="element.value" placeholder="输入搜索关键字、岗位/角色、账户名称等" style="width:350px;" enter-button @search="execSearch('view' , 0 , 10)" />
                        
                        <div style="display:inline; margin-left:15px; margin-right:10px;">
                          <span style="position:relative;" ><span style="color:red;margin-right:0px;position:absolute;left:-10px;top:0px;"></span>所属区域</span>
                          <a-auto-complete v-model="search.province" :data-source="search.provinceSource" placeholder="请输入所属区域！" style="width: 150px"  :filter-option="filterOption" />
                        </div>

                        <div style="display:inline; margin-left:10px; margin-right:10px;">
                          <span style="position:relative;" ><span style="color:red;margin-right:0px;position:absolute;left:-10px;top:0px;"></span>所属板块</span>
                          <a-input v-model="search.zone" :readonly="false" placeholder="请输入所属板块！" style="width:150px; border: 0px solid #fefefe; border-bottom: 1px solid #f0f0f0;"  />
                        </div>

                        <div style="display:inline; margin-left:10px; margin-right:10px;">
                          <span style="position:relative;" ><span style="color:red;margin-right:0px;position:absolute;left:-10px;top:0px;"></span>岗位/角色</span>
                          <a-select mode="single" v-model="search.groupname" placeholder="请输入岗位/角色！" style="width:150px; border: 0px solid #fefefe;  border-bottom: 1px solid #f0f0f0;">
                            <template v-for="(elem,index) in roleList ">
                              <a-select-option :key="elem" :index="index" :value="elem.value">
                                {{ elem.name }}
                              </a-select-option>
                            </template>
                          </a-select>
                        </div>

                        <a-button type="primary" @click="execSearch('view' , 0, 10)" >查询</a-button>
                    </div>

                    <div style="margin-left:20px;">
                      <a-tabs default-active-key="1" @change="callback">
                        <a-tab-pane key="1" tab="列表">
                          <a-empty v-if="data.length == 0" style="margin-top:10%;height:580px;"/>
                          <div v-if="data.length > 0" class="reward-content-table" style="margin-left:0px; margin-bottom:20px; width:98%;"> 
                              <a-list item-layout="horizontal" :data-source="data">
                                <a-list-item v-show=" item.status != 'invalid' " slot="renderItem" slot-scope="item, index" style="position:relative;">
                                  <a-list-item-meta :index="index" :description="`岗位/角色: ${ item.groupname } ，账户名称：${item.userlist_reception_name}，OA账户: ${ item.userlist } ` " @click="execView(item)" >
                                    <a slot="title" @click="execView(item)" >{{ `序号：${index+1}， 所属区域：${ item.zonename }，所属板块：${ item.platename }，填报日期：${item.create_time} ` }}</a>
                                  </a-list-item-meta>
                                </a-list-item>
                              </a-list>
                              <a-divider type="horizontal" />
                              <a-pagination show-size-changer :default-current="1" :showQuickJumper="true" :total="search.total" @showSizeChange="paginationView" @change="paginationView" :pageSizeOptions="['10', '20', '30', '40', '50', '100', '1000', '10000']" > 
                                <template slot="buildOptionText" slot-scope="props">
                                  <span >{{ props.value }}条/页</span>
                                </template>
                              </a-pagination>
                          </div>
                        </a-tab-pane>
                      </a-tabs>
                    </div>

                </div>
                </div>
              </div>

            </a-col>
        </keep-alive>
      </a-row>
    </div>
  </div>
</template>
<script>
export default {
  mixins: [window.mixin],
  data() {
    return {
      getUrlParam:Betools.tools.getUrlParam,
      iswechat:false,
      iswework:false,
      pageName: "系统权限管理",
      momentNewMsg: true,
      activeTabKey: 3,
      acceptType:'*/*',
      uploadURL:'',
      tablename:'bs_admin_group',
      viewname:'bs_admin_group',
      size: 0,
      options:{
        create_time:moment(dayjs().format('YYYY-MM-DD'),'YYYY-MM-DD'),
        in_time:moment(dayjs().format('YYYY-MM-DD'),'YYYY-MM-DD'),
        establish_time:moment(dayjs().format('YYYY-MM-DD'),'YYYY-MM-DD'),
        start_time:moment(dayjs().format('YYYY-MM-DD'),'YYYY-MM-DD'),
        coop_time:moment(dayjs().format('YYYY-MM-DD'),'YYYY-MM-DD'),
        out_time:moment(dayjs().format('YYYY-MM-DD'),'YYYY-MM-DD'),
        datetime:moment(dayjs().format('YYYY-MM-DD'),'YYYY-MM-DD'),
        zoneOptions:JSON.parse(`[{"label":"融量集团","value":"融量集团"},{"label":"地产板块","value":"地产板块","children":[{"label":"集团总部","value":"集团总部"},{"label":"成渝区域","value":"成渝区域"},{"label":"两湖区域","value":"两湖区域"},{"label":"川北区域","value":"川北区域"},{"label":"川南区域","value":"川南区域"},{"label":"中原区域","value":"中原区域"},{"label":"攀西区域","value":"攀西区域"},{"label":"新疆区域","value":"新疆区域"},{"label":"大湾区域","value":"大湾区域"},{"label":"北京区域","value":"北京区域"},{"label":"园林公司","value":"园林公司"}]},{"label":"金融板块","value":"金融板块"},{"label":"物业板块","value":"物业板块"},{"label":"医疗健康板块","value":"医疗健康板块"},{"label":"商业板块","value":"商业板块"},{"label":"合作方财务公司","value":"合作方财务公司"}]`),
      },
      element:{
        value:'',
        stage:'全部',
        caseSType:'全部',
        legalType:'全部',
      },
      search:{
        total:'500',
        zone:'',
        province:'',
        groupname:'',
        provinceSource:[],
      },
      data: [],
      readonly: false,
      userList:[],
      selectedSheet: null,
      sheetName: null,
      sheets: [{ name: "Sheet1", data: [{}] }],
      collection: [{ }],
      userinfo: '',
      usertitle:'',
      columns:[],
      data:[],
      rowSelection:[],
      stageVal:{},
      statusList:['存续','注销','经营异常'],
      natureList:['关联公司','非关联公司'],
      roleList:[{name:'股权管理员',value:'STOCK_OPERATE_ADMIN'},{name:'股权查询员',value:'STOCK_VIEW_ADMIN'},{name:'系统管理员',value:'SYSTEM_ADMIN'},{name:'资质管理员',value:'LICENSE_ADMIN'},{name:'产权管理员',value:'PROPERTY_ADMIN'},{name:'印章保管员',value:'SEAL_ADMIN'},{name:'案件管理员',value:'LEGAL_OPERATE_ADMIN'},{name:'法务管理员',value:'LEGAL_ADMIN'},{name:'物品管理员',value:'COMMON_RECEIVE_BORROW'},{name:'来访管理员',value:'COMMON_VISIT_AUTH'}],
      roleAccessList:{'STOCK_OPERATE_ADMIN':'myreward-access,mydone-access,mytodo-access,myapply-access,companyapply-access,pledgeapply-access,qualificationapply-access,annalsapply-access,companylist-access,subsidyapply-access,alterationapply-access,punishmentapply-access,accountapply-access,licenseapply-access,prolicenseapply-access,otherlicenseapply-access,trademarkapply-access,softwareapply-access,worksapply-access,recordapply-access','STOCK_VIEW_ADMIN':'myreward-access,mydone-access,mytodo-access,myapply-access,companylist-access','SYSTEM_ADMIN':'myreward-access,mydone-access,mytodo-access,myapply-access,accessapply-access','LICENSE_ADMIN':'myreward-access,mytodo-access,mydone-access,myapply-access,licenseapply-access,prolicenseapply-access,otherlicenseapply-access','PROPERTY_ADMIN':'myreward-access,mytodo-access,mydone-access,myapply-access,trademarkapply-access,softwareapply-access,worksapply-access,recordapply-access','SEAL_ADMIN':'myreward-access,mytodo-access,mydone-access,myapply-access','LEGAL_OPERATE_ADMIN':'myreward-access,mytodo-access,mydone-access,myapply-access','LEGAL_ADMIN':'myreward-access,mytodo-access,mydone-access,myapply-access','COMMON_RECEIVE_BORROW':'myreward-access,mytodo-access,mydone-access,myapply-access','COMMON_VISIT_AUTH':'myreward-access,mytodo-access,mydone-access,myapply-access'},
      accessList:[{name:'我的知会',value:'myreward-access'},{name:'我的待办',value:'mytodo-access'},{name:'我的已办',value:'mydone-access'},{name:'我的申请',value:'myapply-access'},{name:'设立公司申请',value:'companyapply-access'},{name:'录入质押申请',value:'pledgeapply-access'},{name:'录入资质申请',value:'qualificationapply-access'},{name:'录入年报申请',value:'annalsapply-access'},{name:'公司工商查询',value:'companylist-access'},{name:'录入补贴记录',value:'subsidyapply-access'},{name:'录入变更记录',value:'alterationapply-access'},{name:'录入处罚记录',value:'punishmentapply-access'},{name:'录入账号记录',value:'accountapply-access'},{name:'录入营业执照',value:'licenseapply-access'},{name:'录入项目证照',value:'prolicenseapply-access'},{name:'录入其他证照',value:'otherlicenseapply-access'},{name:'录入商标信息申请',value:'trademarkapply-access'},{name:'录软件著作权申请',value:'softwareapply-access'},{name:'录作品著作权申请',value:'worksapply-access'},{name:'录入网站备案申请',value:'recordapply-access'},{name:'系统权限申请',value:'accessapply-access'}],
      industryList:[ '地产板块', '金融板块', '物业板块', '医疗健康板块', '商业板块','合作方财务公司'],
      breadcrumb:[{icon:'home',text:'首页',path:'/stock/workspace'},{icon:'user',text:'系统管理',path:'/stock/workspace'},{icon:'form',text:'系统权限管理',path:''}],
      statusType:{'valid':'有效','invalid':'删除'},
      zoneType:{'领地集团总部':'领地集团总部','成渝区域':'成渝区域','两湖区域':'两湖区域','川北区域':'川北区域','川南区域':'川南区域','中原区域':'中原区域','攀西区域':'攀西区域','新疆区域':'新疆区域','大湾区域':'大湾区域','北京区域':'北京区域'},
    };
  },
  activated() {
  },
  mounted() {
    this.queryInfo();
  },
  methods: {
      moment,
      isNull:Betools.tools.isNull,
      deNull:Betools.tools.deNull,

      // 名称过滤
      filterOption(input, option) {
        return (
          option.componentOptions.children[0].text.toUpperCase().indexOf(input.toUpperCase()) >= 0
        );
      },

      // 企业微信登录处理函数
      async  weworkLogin  (codeType = 'search', systemType = 'search', version = 'v4')  {
          /**
           URL直连模式登陆：http://stock.yunwisdom.club:30080/#/?mode=session&mobile=19999763013&account=bWVuZ3Fm
            1. mobile请替换为登录人的mobile。
            2. account请替换为登录人的account，注意account需要使用window.btoa('args')函数处理一下。
           */
          return await Betools.query.weworkLogin(codeType, systemType, version);
      },

      // 执行页面跳转
      async redirectView(path) {
          Betools.tools.isNull(path) ? null: this.$router.push(path);
      },
     
      // 获取基础信息
      async queryInfo() {
        try {
          const tableName = this.tablename;
          this.iswechat = Betools.tools.isWechat(); //查询当前是否微信端
          this.iswework = Betools.tools.isWework(); //查询是否为企业微信
          const weworkinfo = await this.weworkLogin('search','search','v4'); //查询当前登录用户
          this.userinfo = weworkinfo.userinfo;
          this.usertitle = weworkinfo.usertitle;
          this.back = Betools.tools.getUrlParam('back') || '/stock/workspace'; //查询上一页
          this.element.stage = Betools.tools.getUrlParam('stage') || '全部';
          const userinfo = await Betools.storage.getStore('system_userinfo');  //获取用户基础信息
          this.execSearch('view',0,10);
        } catch (error) {
          console.log(error);
        }
      },

      //查询不同状态的数据
      async handleList(tableName , status = 'valid', userinfo, searchSql , page = 0 , size = 10000){
        if(Betools.tools.isNull(userinfo) || Betools.tools.isNull(userinfo.username)){
            return [];
        }
        const condition = `_where=(status,in,${status})${searchSql}&_sort=-id&_p=${page}&_size=${size}`;
        let list = await Betools.manage.queryTableData(tableName ,condition );
        this.search.total = await Betools.manage.queryTableDataCount(tableName, condition);
        list.map((item)=>{ 
            item.create_time = dayjs(item.create_time).format('YYYY-MM-DD'); 
        });
        return list;
      },

      // 记录查看申请
      async execView(elem){
          const { $router } = this;
          $router.push(`/stock/access/accessapply?id=${elem.id}&type=1&tname=案件详情&apply=view&role=view`);
      },

      // 列表执行刷新操作45
      async execFresh(value = '' , page = 0, size = 10){
        await this.execSearch(value, page , size);
      },

      // 列表执行搜索功能
      async execSearch(value = '', page = 0 , size = 10){
        console.log(`exec search ...` , dayjs().format('HH:mm:ss'));
        const tableName = this.viewname;
        const cacheRandomKey = value == 'view' ? ',' + Math.random().toString().slice(2,6) : '';
        const toast = value == 'view' ? vant.Toast.loading({ duration: 3000,  forbidClick: false,  message: '刷新中...', }):null;
        const { element, search } = this;
        const userinfo = await Betools.storage.getStore('system_userinfo');  //获取用户基础信息
        let searchSql = typeof element.value == 'string' ? `~and((groupname,like,~${element.value}~)~or(userlist,like,~${element.value}~)~or(userlist_reception,like,~${element.value}~)~or(userlist_reception_name,like,~${element.value}~)~or(zonename,like,~${element.value}~)~or(platename,like,~${element.value}~)~or(access,like,~${element.value}~))` : '';
        let groupnameSql = search.groupname ? `~and(groupname,eq,${search.groupname})`:``;
        const data = await this.handleList(tableName , `valid`, userinfo, groupnameSql + searchSql , page , size);
        value == 'view' ? (this.data = data)  : null;
        await Betools.tools.sleep(300);
        value == 'view' ? (vant.Toast.clear()) : null;
        debugger;
        return data; 
      },

      // 执行分页查询
      async paginationView(page = 0, size = 10){
        this.execSearch('view', page -1 , size);
      }

  },
};
</script>
<style scoped >
    @import "../../../assets/css/reward.home.css";
    @import "../../../assets/css/reward.apply.css";
</style>
